package com.earl.gsm.web.match;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.earl.gsm.commons.vo.ResultMessage;
import com.earl.gsm.domain.gsm.match.Team;
import com.earl.gsm.domain.sercurity.user.User;
import com.earl.gsm.service.TeamInfoService;
import com.earl.gsm.web.BaseController;
import com.wordnik.swagger.annotations.ApiOperation;

@Controller
@RequestMapping(value = "/match/team")
//@Api(value="Person Rest Service") //修改生成的son路径
public class TeamInfoController extends BaseController {

    private final Logger log = LoggerFactory.getLogger(TeamInfoController.class);

    @Autowired
    private TeamInfoService service;

    private ResultMessage result = null;

    /**
     * GET /users -> get all the users
     */
    @RequestMapping(value = "/all", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "得到所有队伍简易信息", notes = "find All User", httpMethod = "GET", response = User.class, responseContainer = "List")
    public ModelAndView getAll() {
        log.debug("REST request to get all Users");
        result = new ResultMessage();
        result.getResultParm().put("teamList", service.findAll());
        return new ModelAndView("match/allTeam","teamList",service.findAll());
    }

    /**
     * GET /users -> get all the users
     */
    @RequestMapping(value = "/pointMatch/{matchId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "指定赛事下的所有队伍", notes = "find All User", httpMethod = "GET", response = User.class, responseContainer = "List")
    public ModelAndView pointMatch(@PathVariable Long matchId) {
        log.debug("REST request to get all Users");
        return new ModelAndView("match/allTeam","teamList",service.findAll());
    }

    /**
     * GET /users -> get all the users
     */
    @RequestMapping(value = "/preAdd")
    @ApiOperation(value = "指定赛事下的所有队伍", notes = "find All User", httpMethod = "GET", response = User.class, responseContainer = "List")
    public String preAdd() {
        log.debug("REST request to get all Users");
        return "team/addTeam";
    }
    
    @RequestMapping(value="/add")
    @ApiOperation(value = "保存团队信息", notes = "find All User", httpMethod = "GET", response = User.class, responseContainer = "List")
    public ResponseEntity<ResultMessage> compeleteTeamInfo(Team team){
        service.save(team);
        return  new ResponseEntity<ResultMessage>(result, HttpStatus.OK);
    }

    @RequestMapping(value="/update")
    @ApiOperation(value = "更新团队信息", notes = "update Team Info", httpMethod = "GET", response = User.class, responseContainer = "List")
    public ResponseEntity<ResultMessage> compeletePlayerInfo(Team team){
        service.updateByPrimaryKeySelective(team);
        return new ResponseEntity<ResultMessage>(HttpStatus.OK);
    }

    @RequestMapping(value="/delete/{teamId}",method = RequestMethod.POST)
    @ApiOperation(value = "删除团队信息", notes = "update Team Info", httpMethod = "POST", response = User.class, responseContainer = "List")
    public ResponseEntity<ResultMessage> deleteTeamInfo(@PathVariable Long teamId){
        service.delete(teamId);
        return new ResponseEntity<ResultMessage>(HttpStatus.OK);
    }

    @RequestMapping(value="/preUpdate/{teamId}",method = RequestMethod.GET)
    @ApiOperation(value = "预更新队伍信息", notes = "update Team Info", httpMethod = "POST", response = User.class, responseContainer = "List")
    public ModelAndView preUpdate(@PathVariable Long teamId){
//        service.delete(matchId);
        return new ModelAndView("team/preUpdate","team",service.findOne(teamId));
    }
}
